"""
Author : ZhengShiQi
dateTime: 2025/9/11 15:59
FileName: config.py
description: 配置管理
"""
import yaml
import os
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    # 格式：mysql+pymysql://用户名:密码@MySQL服务器IP:端口/数据库名?charset=utf8mb4
    DATABASE_URL: str

    # 其他配置...
    WIREMOCK_URL: str  # WireMock 地址（嵌入式/独立部署的IP）
    WIREMOCK_BIND_ADDRESS: str  # WireMock绑定地址，0.0.0.0表示允许外部访问

    class Config:
        # 从YAML文件加载配置
        @classmethod
        def customise_sources(cls, init_settings, env_settings, file_secret_settings):
            return init_settings, env_settings, file_secret_settings

# 读取YAML配置文件
yaml_config_path = os.path.join(os.path.dirname(__file__), "config.yaml")
if os.path.exists(yaml_config_path):
    with open(yaml_config_path, "r", encoding="utf-8") as f:
        yaml_config = yaml.safe_load(f) or {}
    
    # 使用YAML配置覆盖默认值
    settings = Settings(**yaml_config)
else:
    settings = Settings()